package cloud.xlh.middleware_manage.service.impl;

import cloud.xlh.middleware_manage.domin.ConnectionInfo;
import cloud.xlh.middleware_manage.service.OperateService;
import cloud.xlh.middleware_manage.util.KeepAliveStrategyUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/2/28 13:54
 * @ Description:
 */
@Service
public class OperateServiceImpl implements OperateService {

   /* @Resource
    private OperateMapper operateMapper;*/
/*

    @Override
    public JSONObject operate(MiddleWareOperateInfo middleWareOperateInfo) {
        Integer opType = middleWareOperateInfo.getOpType();
        return doOperate(opType, middleWareOperateInfo);
    }
*/

    @Override
    public Boolean checkKeepAlive(ConnectionInfo connectionInfo) {
        Integer code = connectionInfo.getCode();
        KeepAliveStrategyUtil keepAliveStrategyUtil = KeepAliveStrategyUtil.getStrategyInstance(code);
        return keepAliveStrategyUtil.exKeepAliveStrategy(connectionInfo.getIp() , connectionInfo.getPort() , StringUtils.isEmpty(connectionInfo.getUsername()) ? "" :connectionInfo.getUsername() , StringUtils.isEmpty(connectionInfo.getPassword()) ? "" :connectionInfo.getPassword());
    }

//    private JSONObject doOperate(Integer opType, MiddleWareOperateInfo middleWareOperateInfo) {
//        int rowsForAdd = 0;
//        int rowsForUpdate = 0;
//        int rowsForDelete = 0;
//        JSONObject rsp = new JSONObject();
//        JSONObject head = new JSONObject();
//        head.put("retCode", "PR01");
//        head.put("retInfo", "操作失败");
//        rsp.put("head", head);
//        JSONObject body = new JSONObject();
//        rsp.put("body", body);
//        if (OpTypeEnum.ADD.getCode() == opType) {
//            rowsForAdd = operateMapper.add(middleWareOperateInfo);
//            if (rowsForAdd < 1) {
//                body.put("middleWareOperateInfo", middleWareOperateInfo);
//            }
//        } else if (OpTypeEnum.DELETE.getCode() == opType) {
//            rowsForUpdate = operateMapper.update(middleWareOperateInfo);
//            if (rowsForUpdate < 1) {
//                body.put("middleWareOperateInfo", middleWareOperateInfo);
//            }
//        } else if (OpTypeEnum.UPDATE.getCode() == opType) {
//            rowsForDelete = operateMapper.delete(middleWareOperateInfo);
//            if (rowsForDelete < 1) {
//                body.put("middleWareOperateInfo", middleWareOperateInfo);
//            }
//        } else {
//            return null;
//        }
//        if (rowsForAdd + rowsForUpdate + rowsForDelete != 0) {
//            head.put("retCode", "PR00");
//            head.put("retInfo", "操作成功");
//        }
//        return rsp;
//    }

}
